package cn.genmer.test.security.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局统一异常处理
 *
 * @Author youyq
 * @Date 2021/8/3 10:01
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    private final static Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 功能描述：异常处理
     *
     * @param e 异常参数
     * @return R 返回给前端的异常信息
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseEntity<String> error(Exception e) {
        e.printStackTrace();
        logger.error(String.format("统一异常拦截:%s", e.getMessage()));
        return ResponseEntity.ok("请求失败");
    }
}